home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
SciAn
/
src
/
ScianJpeg.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
3KB
|
172 lines
/*ScianJpeg.c
Robert Sumner
August 17, 1993
Jpeg pseudorecorder*/
#include "Scian.h"
#include "ScianTypes.h"
#include "ScianWindows.h"
#include "ScianIDs.h"
#include "ScianJpeg.h"
#include "ScianRecorders.h"
#ifdef JPEGRECORDER
static long curJpegFrame = 0;
static ObjPtr ReturnTrue(object)
ObjPtr object;
/*Returns true*/
{
return ObjTrue;
}
static ObjPtr PrepareToRecordJpeg(object, nFrames)
ObjPtr object;
long nFrames;
/*Prepares to record nframes*/
{
curJpegFrame = 0;
return ObjTrue;
}
static ObjPtr SnapOneFrameJpeg(object)
ObjPtr object;
/*Do a screen dump of arbitrary size*/
{
int l, b, r, t, w, h;
ObjPtr var;
unsigned long int *JpegArray;
fullscrn();
SetOrigin(0,0);
var = GetVar(object, FRAMEOX);
if (var)
{
l = GetInt(var);
}
else
{
l = 0;
}
var = GetVar(object, FRAMEOY);
if (var)
{
b = GetInt(var);
}
else
{
b = 0;
}
var = GetVar(object, FRAMEWIDTH);
if (var)
{
w = GetInt(var);
}
else
{
w = 0;
}
var = GetVar(object, FRAMEHEIGHT);
if (var)
{
h = GetInt(var);
}
else
{
h = 0;
}
r = l + w - 1;
t = b + h - 1;
if (GetPredicate(object, SAVEWINDOWFRAME))
{
l -= WINBL;
r += WINBR;
b -= WINBB;
t += WINBT;
}
/* advance to the next frame in the directory */
do
{
++curJpegFrame;
sprintf(tempStr, "screen%04d.jpg", curJpegFrame);
} while (fopen(tempStr, "r"));
SetVar(object, FILENAME, NewString(tempStr));
/* Store the name of the current frame in *tempStr */
sprintf(tempStr, "screen%04d.jpg", curJpegFrame);
/* Allocate the memory for the dynamic array */
JpegArray = (unsigned long int *) Alloc(sizeof(unsigned long int) * (w) * (h) );
/* Check to make sure an address was returned */
if (!JpegArray)
{
printf("Insufficient memory to save image.\n");
return ObjFalse;
}
/* Change to full screen mode */
/* fullscrn();
*/
/* Read the pixels into the array */
lrectread(l, b, r, t, JpegArray);
/* Save the array to *tempStr */
printf("Saving frame %04d to 'screen%04d.jpg'\n",curJpegFrame,curJpegFrame);
printf("l=%04d b=%04d r=%04d t=%04d\n",l,b,r,t);
printf("jpaste screen%04d.jpg\n\n",curJpegFrame);
SaveJPEGImagePtr(tempStr, JpegArray, (w), (h));
/* Change out of full screen mode */
endfullscrn();
RestoreOrigin();
/* Free the memory */
SAFEFREE(JpegArray);
return ObjTrue;
}
#ifdef PROTO
void InitJpeg(void)
#else
void InitJpeg()
#endif
/*Create a new screen dump ersatz recorder*/
{
ObjPtr recorder;
recorder = NewRecorder(NULLOBJ, "JPEG", "Compressed JPEG");
SetMethod(recorder, CONNECT, ReturnTrue);
SetMethod(recorder, DISCONNECT, ReturnTrue);
SetMethod(recorder, PREPARETORECORD, PrepareToRecordJpeg);
SetMethod(recorder, STOPRECORDING, ReturnTrue);
SetMethod(recorder, SNAPONEFRAME, SnapOneFrameJpeg);
SetVar(recorder, FRAMESOURCE, NewInt(FS_WINDOW));
SetVar(recorder, ENABLEDSOURCES, NewInt(FB_SCREEN + FB_WINDOW));
RegisterRecorder(recorder);
}
#ifdef PROTO
void KillJpeg(void)
#else
void KillJpeg()
#endif
{
}
#endif